<template>
  <div class="app-container">
    <el-form size="small" inline>
      <el-form-item label="监督员姓名">
        <el-input v-model="query.name" placeholder="请输入监督员姓名" />
      </el-form-item>
      <el-form-item label="是否党员">
        <el-select v-model="query.isParty" placeholder="请选择">
          <el-option
            v-for="item in dict.type.isparty_type"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" @click="getList">查询</el-button>
        <el-button plain icon="el-icon-refresh" @click="handleReset">重置</el-button>
        <el-button type="primary" plain icon="el-icon-plus" size="small" @click="dialogVisible = true">新增</el-button>
        <help></help>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="list" border>
      <el-table-column label="序号" align="center" width="50" type="index" fixed="left" />
      <el-table-column label="姓名" align="center" prop="name" />
      <el-table-column label="性别" align="center">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_user_sex" :value="scope.row.sex" />
        </template>
      </el-table-column>
      <el-table-column label="身份证号" align="center" prop="idCard" />
      <el-table-column label="手机号" align="center" prop="phone" width="110" />
      <el-table-column label="入党日期" align="center" prop="joinDate">
        <template slot-scope="scope">{{ Number(scope.row.joinDate) | moment }}</template>
      </el-table-column>
      <el-table-column label="党内职务" align="center" prop="partyPost" />
      <el-table-column label="是否党员" align="center" prop="isParty">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.isparty_type" :value="scope.row.isParty" />
        </template>
      </el-table-column>
      <el-table-column label="工作单位" align="center" prop="workCompany" />
      <el-table-column label="工作岗位" align="center" prop="workPost" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="small" type="text" @click="handleInfo(scope.row)">详情</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:member:remove']"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="query.pageNum"
      :limit.sync="query.pageSize"
      @pagination="getList"
    />

    <help-dialog :visible.sync="dialogVisible" title="党员详情" @close="handleClose">
      <el-form size="small" label-width="120px" ref="queryParam" :model="queryParam" :rules="rules">
        <el-row>
          <el-col :span="12">
            <el-form-item label="姓名" prop="name">
              <el-input v-model="queryParam.name" placeholder="请输入姓名" />
            </el-form-item>
            <el-form-item label="身份证号" prop="idCard">
              <el-input v-model="queryParam.idCard" placeholder="请输入身份证号" />
            </el-form-item>
            <el-form-item label="出生年月" prop="birthDate">
              <el-date-picker
                v-model="queryParam.birthDate"
                type="date"
                placeholder="请选择"
                value-format="timestamp"
                style="width: 100%"
              ></el-date-picker>
            </el-form-item>
            <el-form-item label="学历" prop="education">
              <el-select v-model="queryParam.education" style="width: 100%" placeholder="请选择">
                <el-option v-for="item in studyOptions" :key="item" :label="item" :value="item"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="是否党员">
              <el-select v-model="queryParam.isParty" placeholder="请选择" style="width: 100%">
                <el-option
                  v-for="item in dict.type.isparty_type"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
            <el-form-item label="党内职务" prop="partyPost">
              <el-input v-model="queryParam.partyPost" placeholder="请输入党内职务" />
            </el-form-item>
            <el-form-item label="工作岗位" prop="workPost">
              <el-input v-model="queryParam.workPost" placeholder="请输入工作岗位" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="性别">
              <el-select v-model="queryParam.sex" placeholder="请选择">
                <el-option
                  v-for="item in dict.type.sys_user_sex"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                ></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="手机号" prop="phone">
              <el-input v-model="queryParam.phone" placeholder="请输入手机号" />
            </el-form-item>
            <el-form-item label="籍贯" prop="nativePlace">
              <el-input v-model="queryParam.nativePlace" placeholder="请输入籍贯" />
            </el-form-item>
            <el-form-item label="所在党支部" prop="partyId">
              <el-select v-model="queryParam.partyId" style="width: 100%" placeholder="请选择">
                <el-option
                  v-for="item in partyTypeList"
                  :key="item.partyId"
                  :label="item.name"
                  :value="item.partyId"
                ></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="入党日期" prop="joinDate">
              <el-date-picker
                v-model="queryParam.joinDate"
                type="date"
                placeholder="请选择"
                value-format="timestamp"
                style="width: 100%"
              ></el-date-picker>
            </el-form-item>
            <el-form-item label="工作单位" prop="workCompany">
              <el-input v-model="queryParam.workCompany" placeholder="请输入工作单位" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-col :span="24">
          <el-form-item label="备注信息" prop="remark">
            <el-input type="textarea" v-model="queryParam.remark" :rows="3" placeholder="请输入备注信息" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="添加附件" prop="enclosure">
            <y-upload :path="[queryParam.enclosure]" limit="1" @onSuccess="onSuccess" />
          </el-form-item>
        </el-col>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="dialogVisible = false">取 消</el-button>
      </div>
    </help-dialog>
  </div>
</template>

<script>
import memberApi from '@/api/party/member'

export default {
  dicts: ['isparty_type', 'sys_user_sex'],
  data() {
    return {
      loading: false,
      query: {
        name: '',
        isParty: '',
        pageNum: 1,
        pageSize: 10
      },
      list: [],
      total: 0,
      dialogVisible: false,
      queryParam: {},
      studyOptions: ['小学', '初中', '高中', '大专', '大学本科', '研究生', '学士', '硕士', '博士'],
      partyTypeList: [],
      rules: {
        name: [{ required: true, message: '请输入姓名', trigger: 'blur' }],
        idCard: [{ required: true, message: '请输入身份证号', trigger: 'blur' }],
        birthDate: [{ required: true, message: '请选择', trigger: 'blur' }],
        education: [{ required: true, message: '请选择', trigger: 'blur' }],
        partyPost: [{ required: true, message: '请输入党内职务', trigger: 'blur' }],
        workPost: [{ required: true, message: '请输入工作岗位', trigger: 'blur' }],
        phone: [{ required: true, message: '请输入手机号', trigger: 'blur' }],
        nativePlace: [{ required: true, message: '请输入籍贯', trigger: 'blur' }],
        partyId: [{ required: true, message: '请选择', trigger: 'blur' }],
        joinDate: [{ required: true, message: '请选择', trigger: 'blur' }],
        workCompany: [{ required: true, message: '请输入工作单位', trigger: 'blur' }]
      }
    }
  },
  created() {
    this.getList()
    this.getPartyList()
  },
  methods: {
    getList() {
      this.loading = true
      memberApi.memberList(this.query).then((res) => {
        this.list = res.rows
        this.total = res.total
        this.loading = false
      })
    },
    handleReset() {
      this.query = {
        name: '',
        isParty: '',
        pageNum: 1,
        pageSize: 10
      }
      this.getList()
    },
    onSuccess(file) {
      this.queryParam.enclosure = file.router
    },
    handleInfo(row) {
      this.uploadedFileList = []
      memberApi.memberDetail(row.id).then((res) => {
        this.queryParam = res.data
        this.dialogVisible = true
      })
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      this.$modal
        .confirm('确认删除吗？')
        .then(function () {
          return memberApi.delMember(row.id)
        })
        .then(() => {
          this.getList()
          this.$modal.msgSuccess('删除成功')
        })
        .catch(() => {})
    },
    handleClose() {
      this.queryParam = {}
    },
    getPartyList() {
      memberApi.partyList().then((res) => {
        this.partyTypeList = res.rows
      })
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs['queryParam'].validate((valid) => {
        if (valid) {
          if (this.queryParam.id != null) {
            memberApi.updateMember(this.queryParam).then((response) => {
              this.$modal.msgSuccess('修改成功')
              this.dialogVisible = false
              this.getList()
            })
          } else {
            memberApi.addMember(this.queryParam).then((response) => {
              this.$modal.msgSuccess('新增成功')
              this.dialogVisible = false
              this.getList()
            })
          }
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped></style>
